package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.request.DeptRequest;
import com.bodu.system.entity.vo.DeptVo;
import com.bodu.system.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author r.guo
 * @since 2019-05-25
 */
@Api(tags = "单位管理")
@RestController
@RequestMapping("/dept")
public class DeptController extends AbstractCommonController<DeptService, DeptRequest, DeptVo>{

    private final DeptService deptService;

    public DeptController(DeptService deptService) {
        this.deptService = deptService;
    }

    @TraceLog()
    @ApiOperation("保存单位信息")
    @PostMapping
    public Result save(@RequestBody DeptRequest deptRequest) {
        return super.save(deptService, deptRequest);
    }

    @TraceLog()
    @ApiOperation("更新单位信息")
    @PutMapping()
    public Result update(@RequestBody DeptRequest deptRequest) {
        return super.update(deptService, deptRequest);
    }

    @TraceLog()
    @ApiOperation("查询机构列表")
    @PostMapping("listPage")
    public Result listPage(@RequestBody ParamReq<DeptRequest> req)  {
        return super.listPage(deptService, req);
    }

    @TraceLog()
    @ApiOperation("查询机构数量")
    @PostMapping("countPage")
    public Result countPage(@RequestBody ParamReq<DeptRequest> req)  {
        return super.countPage(deptService, req);
    }

    @TraceLog()
    @ApiOperation("查询机构-分页")
    @PostMapping("page")
    public Result page(@RequestBody ParamReq<DeptRequest> req)  {
        return super.page(deptService, req);
    }

    /**
     * 循环Permit
     * @param
     * @return
     */
    @TraceLog()
    @ApiOperation("循环Loop")
    @GetMapping("loopList")
    public Result loopList() {
        return Result.success(deptService.loopList());
    }

    @TraceLog()
    @ApiOperation("删除单位信息")
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return super.delete(deptService, id);
    }

    @TraceLog()
    @ApiOperation("删除单位信息")
    @DeleteMapping("deletes/{ids}")
    public Result batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(deptService, ids);
    }

    @TraceLog()
    @ApiOperation("查询单位信息")
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(deptService, id);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
